<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue"></script>
</head>
<body>
    <div id="app">
        <h1>{{ product }}库存信息</h1>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue"></script>
    <script>
        const app = new Vue({
            el: '#app',
            data: {
                product: 'iPhone X'
            }
        });
    </script>
    <div id="app">
        <h1>库存信息</h1>
        <hr>
        <ul>
            <li v-for="product in products">
                {{ product.name }} - {{ product.quantity }}
                <span v-if="product.quantity === 0">
                    已经售罄
                </span>
            </li>
        </ul>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue"></script>
    <script>
        const app = new Vue({
            el: '#app',
            data: {
                products: [
                    {"id": 1, "name": "iPhone X", "quantity": 20},
                    {"id": 2, "name": "华为 Mate20", "quantity": 0},
                    {"id": 3, "name": "小米 Mix3", "quantity": 50}
                ]
            }
        });
    </script>
    <div id="app">
        <h1>库存信息</h1>
        <hr>
        <ul>
            <li v-for="product in products">
                {{ product.name }} - {{ product.quantity }}
                <span v-if="product.quantity === 0">
                    已经售罄
                </span>
            </li>
        </ul>
        <h2>库存总量：{{ totalQuantity }}台</h2>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue"></script>
    <script>
        const app = new Vue({
            el: '#app',
            data: {
                products: [
                    {"id": 1, "name": "iPhone X", "quantity": 20},
                    {"id": 2, "name": "华为 Mate20", "quantity": 0},
                    {"id": 3, "name": "小米 Mix3", "quantity": 50}
                ]
            },
            computed: {
                totalQuantity() {
                    return this.products.reduce((sum, product) => {
                        return sum + product.quantity
                    }, 0);
                }
            }
        });
    </script>
    <div id="app">
        <h1>库存信息</h1>
        <hr>
        <ul>
            <li v-for="product in products">
                {{ product.name }} - {{ product.quantity }}
                <span v-if="product.quantity === 0">
                    已经售罄
                </span>
                <button @click="product.quantity += 1">
                    增加库存
                </button>
            </li>
        </ul>
        <h2>库存总量：{{ totalQuantity }}台</h2>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue"></script>
    <script>
        const app = new Vue({
            el: '#app',
            data: {
                products: [
                    {"id": 1, "name": "iPhone X", "quantity": 20},
                    {"id": 2, "name": "华为 Mate20", "quantity": 0},
                    {"id": 3, "name": "小米 Mix3", "quantity": 50}
                ]
            },
            computed: {
                totalQuantity() {
                    return this.products.reduce((sum, product) => {
                        return sum + product.quantity
                    }, 0);
                }
            }
        });
    </script>
    <div id="app">
        <h1>库存信息</h1>
        <hr>
        <ul>
            <li v-for="product in products">
                {{ product.name }} - 
                <input type="number" v-model.number="product.quantity" min="0">
                <span v-if="product.quantity === 0">
                    已经售罄
                </span>
                <button @click="product.quantity += 1">
                    增加库存
                </button>
            </li>
        </ul>
        <h2>库存总量：{{ totalQuantity }}台</h2>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue"></script>
    <script>
        const app = new Vue({
            el: '#app',
            data: {
                products: [
                    {"id": 1, "name": "iPhone X", "quantity": 20},
                    {"id": 2, "name": "华为 Mate20", "quantity": 0},
                    {"id": 3, "name": "小米 Mix3", "quantity": 50}
                ]
            },
            computed: {
                totalQuantity() {
                    return this.products.reduce((sum, product) => {
                        return sum + product.quantity
                    }, 0);
                }
            }
        });
    </script>
    <div id="app">
        <h2>库存信息</h2>
        <ul>
            <li v-for="product in products">
                {{ product.name }} - {{ product.quantity }}
                <span v-if="product.quantity === 0">
                    已经售罄
                </span>
            </li>
        </ul>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue"></script>
    <script>
        const app = new Vue({
            el: '#app',
            data: {
                products: []
            },
            created() {
                fetch('https://jackfrued.top/api/products')
                    .then(response => response.json())
                    .then(json => {
                        this.products = json
                    });
            }
        });
    </script>
</body>
</html>